import { NOl } from "naive-ui";
import { getSlotsDom } from "../utils";
import type { HTMLAttributes } from "vue";
import type { BaseComponentType } from "../types";
import type { OlProps } from "naive-ui";
export type OlFactoryConstructorType = {
  props?: OlProps;
  attrs?: HTMLAttributes;
  defaOltSlot?: BaseComponentType;
};
export class OlFactory {
  private attrs: HTMLAttributes = {};
  private props: OlProps = {};
  private defaOltSlot: BaseComponentType = null;
  constructor(data?: OlFactoryConstructorType) {
    if (data?.props) this.setProps(data.props);
    if (data?.attrs) this.setAttrs(data.attrs);
    if (data?.defaOltSlot) this.setDefaOlt(data.defaOltSlot);
  }
  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this;
  }
  setProps(props: OlProps) {
    this.props = props;
    return this;
  }
  setDefaOlt(component: BaseComponentType) {
    this.defaOltSlot = component;
    return this;
  }
  create() {
    return (
      <NOl {...this.attrs} {...this.props}>
        {{
          defaOlt: () => getSlotsDom(this.defaOltSlot),
        }}
      </NOl>
    );
  }
}
